package myjava.algorithm;

import java.util.ArrayList;
import java.util.HashMap;

public class TwoSum {
	
	public static int[] twoSum(int[] numbers, int target) {
		// Start typing your Java solution below  
        // DO NOT write main() function  
        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();  
        int n = numbers.length;  
        int[] result = new int[2];  
        for (int i = 0; i < numbers.length; i++)  
        {  
            if (map.containsKey(target - numbers[i]))  
            {  
                result[0] = map.get(target-numbers[i]) + 1;  
                result[1] = i + 1;  
                break;  
            }  
            else  
            {  
                map.put(numbers[i], i);  
            }  
        }  
        return result; 
        
    }
	
	public static void main(String[] args) {
		int[] numbers = {4,4,5,12};
		int[] result = twoSum(numbers,9);
		System.out.println(result[0] + " " + result[1]);
	}
}
